<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Return part of a string</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.grapheme-strstr.html">grapheme_strstr</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ref.intl.idn.html">IDN 函数</a></div>
 <div class="up"><a href="ref.intl.grapheme.html">Grapheme 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.grapheme-substr" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">grapheme_substr</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PECL intl &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">grapheme_substr</span> &mdash; <span class="dc-title">Return part of a string</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.grapheme-substr-description">
  <h3 class="title">说明</h3>
  <p class="para">过程化风格</p>
  <div class="methodsynopsis dc-description">
   <span class="type">int</span> <span class="methodname"><strong>grapheme_substr</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$string</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$start</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$length</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   Return part of a string
  </p> 
 </div>


 <div class="refsect1 parameters" id="refsect1-function.grapheme-substr-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">string</code></em></dt>

     <dd>

      <p class="para">
       The input string. Must be valid UTF-8. 
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">start</code></em></dt>

     <dd>

      <p class="para">
       Start position in default grapheme units.
       If $start is non-negative, the returned string will start at the
       $start&#039;th position in $string, counting from zero. If $start is negative,
       the returned string will start at the $start&#039;th grapheme unit from the 
       end of string.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">length</code></em></dt>

     <dd>

      <p class="para">
       Length in grapheme units.
       If $length  is given and is positive, the string returned will contain
       at most $length grapheme units beginning from $start (depending on the 
       length of string). If $length is given and is negative, then
       that many grapheme units will be omitted from the end of string (after the
       start position has been calculated when a start is negative). If $start
       denotes a position beyond this truncation, <strong><code>FALSE</code></strong> will be returned. 
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

   
 
 <div class="refsect1 returnvalues" id="refsect1-function.grapheme-substr-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the extracted part of $string.   
  </p>
 </div>

 
 <div class="refsect1 changelog" id="refsect1-function.grapheme-substr-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.4</td>
       <td>
        If <em><code class="parameter">length</code></em> is given and positive and the
        argument string is shorter than the specified length, all the rest of
        the string according to <em><code class="parameter">start</code></em> parameter is
        returned. Previously, <strong><code>FALSE</code></strong> was returned. 
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>



 <div class="refsect1 examples" id="refsect1-function.grapheme-substr-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-2621">
   <p><strong>Example #1 <span class="function"><strong>grapheme_substr()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$char_a_ring_nfd&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"a\xCC\x8A"</span><span style="color: #007700">;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;'LATIN&nbsp;SMALL&nbsp;LETTER&nbsp;A&nbsp;WITH&nbsp;RING&nbsp;ABOVE'&nbsp;(U+00E5)&nbsp;normalization&nbsp;form&nbsp;"D"<br /></span><span style="color: #0000BB">$char_o_diaeresis_nfd&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"o\xCC\x88"</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;'LATIN&nbsp;SMALL&nbsp;LETTER&nbsp;O&nbsp;WITH&nbsp;DIAERESIS'&nbsp;(U+00F6)&nbsp;normalization&nbsp;form&nbsp;"D"<br /><br /></span><span style="color: #007700">print&nbsp;</span><span style="color: #0000BB">urlencode</span><span style="color: #007700">(</span><span style="color: #0000BB">grapheme_substr</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">"ao"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$char_a_ring_nfd&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"bc"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$char_o_diaeresis_nfd&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"O"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;-</span><span style="color: #0000BB">1&nbsp;</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <p class="para">以上例程会输出：</p>
  <div class="example-contents screen">
<div class="cdata"><pre>
a%CC%8Abco%CC%88
</pre></div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.grapheme-substr-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.grapheme-extract.html" class="function" rel="rdfs-seeAlso">grapheme_extract()</a> - Function to extract a sequence of default grapheme clusters from a text buffer, which must be encoded in UTF-8.</span></li>
    <li class="member">
     <a href="http://unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries" class="link external">&raquo;&nbsp;
      Unicode Text Segmentation: Grapheme Cluster Boundaries
     </a>
    </li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.grapheme-strstr.html">grapheme_strstr</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ref.intl.idn.html">IDN 函数</a></div>
 <div class="up"><a href="ref.intl.grapheme.html">Grapheme 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
